package cn.zymall.goods.controller;

import cn.zymall.common.controller.crud.BaseController;
import cn.zymall.common.model.Spu;
import cn.zymall.common.model.UserCollect;
import cn.zymall.common.utils.response.HttpResult;
import cn.zymall.goods.service.SpuService;
import com.github.pagehelper.PageInfo;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lxh
 * @Description TODO
 * @date 2020/8/21 16:15
 * @Classname SpuController
 **/
@RestController
@RequestMapping("/spu")
public class SpuController extends BaseController<SpuService, Spu> {


    @Autowired
    private SpuService spuService;


    //系统端

    @GetMapping("/findAll")
    public List<Spu> findAll() {
        return spuService.findAll();
    }

    @PostMapping("/add")
    public Spu add(Spu spu) {

        spuService.add(spu);
        return spu;
    }


    /**
     * 添加商品详情
     *
     * @param spu
     */
    @PostMapping("/addSpuDetail")
    public void addSpuDetail(Spu spu) {
        spuService.addSpuDetail(spu);
    }


    /**
     * 修改商品信息
     *
     * @param spu
     */
    @PostMapping("/amend")
    public void amend(Spu spu) {
        spuService.amend(spu);
    }


    /**
     * 组合查询
     *
     * @param spu
     * @return
     */
    @GetMapping("/composeFind")
    public List<Spu> composeFind(Spu spu) {
        System.out.println(spu);
        return spuService.composeFind(spu);
    }


    /**
     * 审核商品
     *
     * @param spu
     */
    @PostMapping("/examineStatus")
    public void examineStatus(Spu spu) {
        spuService.examineStatus(spu);
    }


    /**
     * 逻辑删除商品
     *
     * @param id
     */
    @PostMapping("/deleteExamineStatus/{id}")
    public void deleteExamineStatus(@PathVariable(name = "id") Integer id) {
        spuService.deleteExamineStatus(id);
    }


    //商家端


    /**
     * 提交审核
     *
     * @param spu
     */
    @PostMapping("/submitExamine")
    public void submitExamine(Spu spu) {
        spuService.submitExamine(spu);
    }


    /**
     * 是否为推荐商品
     *
     * @param spu
     */
    @PostMapping("/updateSpuRecommend")
    public void updateSpuRecommend(Spu spu) {
        System.out.println(spu);
        spuService.updateSpuRecommend(spu);
    }

    /**
     * 根据用户查询收藏的商品
     */
    @GetMapping("/getCollectSpu")
    public List<Spu> getCollectSpu(UserCollect userCollect) {
        return spuService.getCollectSpu(userCollect);
    }

    /**
     * 批量删除用户收藏的商品
     *
     * @return
     */
    @PostMapping("/removeCollectSpu")
    public HttpResult removeList(@RequestBody Spu spu) {
        return spuService.removeCollectSpu(spu.getList());
    }






    /**
     * 根据商品id查询商品
     * * @param id
     * @return
     */
    @GetMapping("/findByIdSpu/{id}")
    public Spu findByIdSpu(@PathVariable(name = "id") Integer id){
        return spuService.findByIdSpu(id);
    }







    /**
     * 查询所有，多条件查询
     * @return
     */
    @GetMapping("/findAllSpu")
    public PageInfo<Spu> findAllSpu(Integer page, Integer rows){
        return spuService.findAllSpu(page,rows);
    }

}
